package com.isaiah.queue;

/**
 * @Title: 循环队列
 * @Description: ${todo}
 * @author: Haijun
 * @emial: isaiah@sohu.com
 * @date 2020/4/816:06
 */
public class LoopQueue<E> implements Queue<E>{
    private E[] data;
    private int front, tail;
    private int size;

    public LoopQueue(int capacity){
        this.data = (E[]) new Object[capacity];
        this.front = 0;
        this.tail = 0;
        this.size = 0;
    }
    public LoopQueue(){
        this(10);
    }

    private void resize(int newCapacity){
        // 创建一个新数组
        E[] newData = (E[]) new Object[newCapacity ];
        // 进行元素搬家
        for (int i = 0; i < size; i ++){
            newData[i] = data[(i + front) % data.length];
        }
        // data指向新数组
        data = newData;
        front = 0;
        tail = size;
    }
    @Override
    public void enqueue(E e) {
        if ((tail + 1) % data.length == front){

        }
    }

    @Override
    public E dequque() {
        return null;
    }

    @Override
    public E getFront() {
        return null;
    }

    @Override
    public int getSize() {
        return size;
    }

    public int getCapacity(){
        return data.length - 1;
    }

    @Override
    public boolean isEmpty() {
        return front == tail;
    }
}
